<?php

class NotActiveOnDeleteBehavior extends CActiveRecordBehavior
{
	public function beforeDelete($event)
	{
		if(!$this->owner->getIsNewRecord())
		{
			Yii::trace(get_class($this->getOwner()).'.'.get_class($this).'.beforeDelete()','app.components.behaviors');
			$this->owner->is_active='0';
			$this->owner->save();
			$event->isValid = false;
		}
		else
			throw new CDbException(Yii::t('yii','The active record cannot be deleted because it is new.'));
	}
}